/**
 * 
 */
package com.xbang.core.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.xbang.core.dao.search.component.SearchComponent;
import com.xbang.core.page.Page;
import com.xbang.core.page.Result;

/**
 * @author dev.zhang
 * 
 */
public interface BaseService {

	/**合并对象并保存
	 * @param object
	 * @return
	 * @throws Exception
	 */
	public void merge(Object object) throws Exception;

	/**
	 * 保存对象
	 * 
	 * @param object
	 *            Entity
	 * @return
	 * @throws Exception
	 */
	public Serializable save(Object object) throws Exception;

	/**
	 * 删除对象
	 * 
	 * @param object
	 *            Entity
	 * @throws Exception
	 */
	public void delete(Object object) throws Exception;

	/**
	 * 删除指定Class的Entity
	 * 
	 * @param clazz
	 *            Entity class
	 * @param id
	 *            key
	 * @throws Exception
	 */
	public void delete(Class clazz, Serializable id) throws Exception;

	/**
	 * 得到对象
	 * 
	 * @param clazz
	 *            Entity class
	 * @param id
	 *            key
	 * @return
	 * @throws Exception
	 */
	public Object getObject(Class clazz, Serializable id) throws Exception;

	/**
	 * 更新对象
	 * 
	 * @param object
	 *            Entity
	 * @throws Exception
	 */
	public void update(Object object) throws Exception;

	/**
	 * 获得对象列表
	 * 
	 * @param clazz
	 *            Entity clazz
	 * @return
	 * @throws Exception
	 */
	public List getObjects(Class clazz) throws Exception;

	/**
	 * Save or update an object using hibernate persistent
	 * 
	 * @param object
	 */
	public void saveOrUpdate(Object object);

	/**
	 * Load an object by persistent class and its id, using first level cache and returns proxy first
	 * 
	 * @param persistentClass
	 * @param id
	 * @return
	 */
	public Object load(Class persistentClass, Serializable id);

	/**
	 * Get an object by persistent class and its id, will returns null if the object does not exist
	 * 
	 * @param persistentClass
	 * @param id
	 * @return
	 */
	public Object get(Class persistentClass, Serializable id);

	/**
	 * Load all the objects by persistent class
	 * 
	 * @param persistentClass
	 * @return
	 */
	public List loadAll(Class persistentClass);

	/**
	 * Get the count of a certain persistent class
	 * 
	 * @param persistentClass
	 * @return
	 */
	public int count(Class persistentClass);

	/**
	 * List items from beginIndex to a maxResult from a persistent class
	 * 
	 * @param persistentClass
	 * @param beginIndex
	 * @param maxResult
	 * @return
	 */
	public List list(Class persistentClass, int beginIndex, int maxResult);

	/**
	 * List items by page from a persistent class
	 * 
	 * @param persistentClass
	 * @param page
	 * @return
	 */
	public Result listByPage(Class persistentClass, Page page);

	/**
	 * Search for an int value by a hql sentence and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @return
	 */
	public int searchForInt(String sentence, Map parameters);

	/**
	 * Search for a list by a hql sentence and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @return
	 */
	public List searchForList(String sentence, Map parameters);

	/**
	 * Search for a list from beginIndex to a maxResult by a hql and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @param beginIndex
	 * @param maxResult
	 * @return
	 */
	public List searchForList(String sentence, Map parameters, int beginIndex, int maxResult);

	/**
	 * Search for a list by page according to a hql and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @param page
	 * @return
	 */
	public Result searchByPage(String sentence, Map parameters, Page page);

	/**
	 * Search for a list by search component according to a hql template
	 * 
	 * @param sentenceTemplate
	 * @param searchComponent
	 * @return
	 */
	public List searchForList(String sentenceTemplate, SearchComponent searchComponent);

	/**
	 * Search by page for a list using search component according to a hql template
	 * 
	 * @param sentenceTemplate
	 * @param searchComponent
	 * @param page
	 * @return
	 */
	public Result searchByPage(String sentenceTemplate, SearchComponent searchComponent, Page page);

	/**
	 * Query for an int value by a sql and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @return
	 */
	public int queryForInt(String sentence, Map parameters);

	/**
	 * Query for an int value by a sql and a bean wrapped with parameters
	 * 
	 * @param sentence
	 * @param parameterBean
	 * @return
	 */
	public int queryForInt(String sentence, Object parameterBean);

	/**
	 * Query for a list by a sql and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @return
	 */
	public List<Map> queryForList(String sentence, Map parameters);

	/**
	 * Search for a list from beginIndex to a maxResult by a sql and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @param beginIndex
	 * @param maxResult
	 * @return
	 */
	public List<Map> queryForList(String sentence, Map parameters, int beginIndex, int maxResult);

	/**
	 * Search for a list by page according to a sql and parameters
	 * 
	 * @param sentence
	 * @param parameters
	 * @param beginIndex
	 * @param maxResult
	 * @return
	 */
	public Result queryByPage(String sentence, Map parameters, Page page);

	/**
	 * Query for a list value by a sql and a bean wrapped with parameters
	 * 
	 * @param sentence
	 * @param parameterBean
	 * @return
	 */
	public List<Map> queryForList(String sentence, Object parameterBean);

	/**
	 * Query for a list by a sql and parameters, the return should be a single row and can be convert to returnClass
	 * 
	 * @param sentence
	 * @param parameters
	 * @param resultClass
	 * @return
	 */
	public List queryForList(String sentence, Map parameters, Class resultClass);

	/**
	 * Query for a list by a sql and a bean wrapped with parameters, the return should be a single row and can be
	 * convert to returnClass
	 * 
	 * @param sentence
	 * @param parameterBean
	 * @param resultClass
	 * @return
	 */
	public List queryForList(String sentence, Object parameterBean, Class resultClass);

	/**
	 * Query for a list by searchComponent using a sql template
	 * 
	 * @param sentenceTemplate
	 * @param searchComponent
	 * @return
	 */
	public List queryForList(String sentenceTemplate, SearchComponent searchComponent);

	/**
	 * 执行SQL语句
	 * 
	 * @param sqlSentence
	 * @param parameters
	 * @throws Exception
	 */
	public void execute(String sqlSentence, Map parameters) throws Exception;
}
